package com.youfang.sixthmedia.message;

import org.json.JSONArray;
import org.json.JSONObject;

import com.youfang.sixthmedia.common.YoufangContext;
import com.youfang.sixthmedia.message.model.User;
import com.youfang.sixthmedia.net.Response;

/**
 * 获取新楼房列表请求
 * 
 * @author Administrator
 * 
 */
public class GetuserbyusernameResponse extends Response {

	private int userid;
	private String nickname = "";
	private int sex;
	private String introduce = "";
	private String logourl;
	private String phone;
	private String mobile;
	private String email;
	private boolean ispublic;
	private String username = "";
	private double lat;
	private double lon;
	private boolean isbuddy;

	public void syncToUser() {
		User user = YoufangContext.getUser();
		user.email = email;
		user.introduce = introduce;
		user.ispublic = ispublic ? 1 : 0;
		user.logourl = logourl;
		user.mobile = mobile;
		user.phone = phone;
		user.sex = sex;
		YoufangContext.saveUserAndStartMessageService(user);

	}

	@Override
	protected void decodeBody(JSONObject bodyJSON) throws Exception {

		JSONArray arr = bodyJSON.getJSONArray("data");
		if (arr.length() == 0) {
			return;
		}

		JSONObject o = arr.getJSONObject(0);

		userid = getInt(o, "userid");
		nickname = getString(o, "nickname");
		sex = getInt(o, "sex");
		introduce = getString(o, "introduce");
		logourl = getString(o, "logourl");
		phone = getString(o, "phone");
		mobile = getString(o, "mobile");
		email = getString(o, "email");
		ispublic = getInt(o, "ispublic") == 1;
		username = getString(o, "username");
		lat = getDouble(o, "lat");
		lon = getDouble(o, "lon");

		try {
			// in case,uses is not logined ,this field will return int zero
			isbuddy = o.getBoolean("isbuddy");
		} catch (Exception e) {
			// ignore
		}

	}

	public int getUserid() {
		return userid;
	}

	public void setUserid(int userid) {
		this.userid = userid;
	}

	public String getNickname() {
		return nickname;
	}

	public void setNickname(String nickname) {
		this.nickname = nickname;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public String getIntroduce() {
		return introduce;
	}

	public void setIntroduce(String introduce) {
		this.introduce = introduce;
	}

	public String getLogourl() {
		return logourl;
	}

	public void setLogourl(String logourl) {
		this.logourl = logourl;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean isIspublic() {
		return ispublic;
	}

	public void setIspublic(boolean ispublic) {
		this.ispublic = ispublic;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public double getLat() {
		return lat;
	}

	public void setLat(double lat) {
		this.lat = lat;
	}

	public double getLon() {
		return lon;
	}

	public void setLon(double lon) {
		this.lon = lon;
	}

	public boolean isIsbuddy() {
		return isbuddy;
	}

	public void setIsbuddy(boolean isbuddy) {
		this.isbuddy = isbuddy;
	}

}
